package com.xinjiang.electricpower.feign.controller;

import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.system.api.RemoteUserService;
import com.ruoyi.system.api.domain.SysStaff;
import com.ruoyi.system.api.domain.SysUser;
import com.xinjiang.electricpower.mapper.SysOrgMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;


/**
 * @author feizhao
 * @date 2022/11/15
 * @apiNote 远程调用员工信息控制层
 */
@RestController
@RequestMapping("/xinjiang-power-supply-station/remote-system-staff")
@Api(value = "系统公用模块-员工信息", tags = "系统公用模块-员工信息")
@Validated//有此注解，才会校验游离的参数
@Slf4j
@RequiredArgsConstructor
public class RemoteStaffController {

    private final  RemoteUserService remoteUserService;
    private final TokenService tokenService;
    private final SysOrgMapper sysOrgMapper;

        /**
     * @return R<Long> 员工信息
     * @description 查询员工信息
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询员工信息", notes = "查询员工信息")
    public AjaxResult getStaff() {
        //获取当前用户的部门id，只查询自己部门的用户
        String deptId = tokenService.getLoginUser().getSysUser().getDeptId();
        List<SysStaff> list = sysOrgMapper.getUserByDeptId(deptId);
        log.info("获取用户信息：{}" ,list);
        return AjaxResult.success(list);
    }

    /** object集合转换为对象的集合 */
    public static <T> List<T> objToList(Object obj, Class<T> cla) {
        List<T> list = new ArrayList<T>();
        if (obj instanceof ArrayList<?>) {
            for (Object o : (List<?>) obj) {
                list.add(cla.cast(o));
            }
            return list;
        }
        return null;
    }
}
